import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-11-17
 * Time: 17:07
 * To BE A Better Person-2020-3-2
 */
@WebServlet("/login")
public class loginservlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html; charset=utf8");
        String username=req.getParameter("username");
        String passwd=req.getParameter("password");
        if(username ==null || username.equals("")||passwd==null||passwd.equals("")){
            resp.getWriter().write("请重新登录");
            return;
        }
        if(!username.equals("krik")||!passwd.equals("lakers26")){
            resp.getWriter().write("请输入正确的用户名或密码");
            return;
        }
        //获取传来的信息
        HttpSession session=req.getSession(true);
        session.setAttribute("username","krik");
        Integer visittime= (Integer) req.getAttribute("visitime");
        if(visittime == null){
            req.setAttribute("visittime",0);
        }else{

        }
        resp.setStatus(302);
        resp.setHeader("Location","127.0.0.1:8080/CookieLogin/index");
    }
}
